<!DOCTYPE html>
<html>
<head>
    <title>DBC 解析器调试</title>
</head>
<body>
    <h1>DBC 解析器调试</h1>
    <div id="output"></div>
    
    <script src="dbc-parser.js"></script>
    <script>
        function log(message) {
            document.getElementById('output').innerHTML += message + '<br>';
        }
        
        function testTokenizer() {
            log('=== 测试词法分析器 ===');
            
            const testContent = 'VERSION "EmptyFile.dbc"';
            log('测试内容: ' + testContent);
            
            try {
                const tokenizer = new DBCTokenizer(testContent);
                
                log('--- Token 分析 ---');
                let token = tokenizer.getNextToken();
                log('Token 1: ' + token.type + ' | ' + token.image);
                
                token = tokenizer.getNextToken();
                log('Token 2: ' + token.type + ' | ' + token.image);
                
                token = tokenizer.getNextToken();
                log('Token 3: ' + token.type + ' | ' + token.image);
                
            } catch (error) {
                log('词法分析错误: ' + error.message);
            }
        }
        
        function testParser() {
            log('<br>=== 测试解析器 ===');
            
            const testContent = 'VERSION "EmptyFile.dbc"';
            
            try {
                const result = parseDBCContent(testContent, 'test.dbc');
                log('解析成功!');
                log('版本: ' + result.version);
            } catch (error) {
                log('解析错误: ' + error.message);
            }
        }
        
        function testRealFile() {
            log('<br>=== 测试真实文件内容 ===');
            
            const realContent = `VERSION "EmptyFile.dbc"

NS_ : 
	CM_
	BA_DEF_
	BA_
	VAL_

BS_:

BU_: TestNode1 TestNode2

BO_ 294 TEST_FRAME_XXX: 8 TestNode
 SG_ PARAM_1 : 7|8@0+ (1,0) [0|0] "" TestNode2
`;
            
            try {
                const result = parseDBCContent(realContent, 'big-endian-1.dbc');
                log('真实文件解析成功!');
                log('版本: ' + result.version);
                log('帧数量: ' + result.frames.length);
                if (result.frames.length > 0) {
                    log('第一个帧: ' + result.frames[0].name);
                }
            } catch (error) {
                log('真实文件解析错误: ' + error.message);
            }
        }
        
        // 运行测试
        testTokenizer();
        testParser();
        testRealFile();
    </script>
</body>
</html> 